import type { GreasyForkElements } from '../../../../../../../../../types/constants/personalization/greasy_fork'
import {
  PAGE_ELEMENTS,
  SUPPORTED_PLATFORMS,
} from '../../../../../../../../../types/constants'
import { DiscussionsPage } from '../discussions'

// 测试链接：https://greasyfork.org/zh-CN/discussions/development
export class DiscussionsDevelopmentPage {
  elements: GreasyForkElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.GREASY_FORK]
  private static instance: DiscussionsDevelopmentPage
  private discussionsPage: DiscussionsPage = DiscussionsPage.getInstance()
  private discussionListSelector: string = '.width-constraint .discussion-list'
  private readonly hasDiscussionList: boolean = false

  constructor() {
    this.hasDiscussionList = $(this.discussionListSelector) && $(this.discussionListSelector).length > 0
  }

  /**
   * 获取单例实例
   */
  public static getInstance(): DiscussionsDevelopmentPage {
    if (!DiscussionsDevelopmentPage.instance) {
      DiscussionsDevelopmentPage.instance = new DiscussionsDevelopmentPage()
    }
    return DiscussionsDevelopmentPage.instance
  }

  init(): void {
    if (!this.hasDiscussionList)
      return

    this.discussionsPage.init()
  }

  getMainStyles(): string {
    return this.hasDiscussionList ? this.discussionsPage.getMainStyles() : ''
  }
}
